package com.yzh.homework;

import java.util.Arrays;

/**
 * @author 于振晗
 * @title: Bubbling
 * @description: TODO 冒泡排序
 * @date 2020年09月01日
 * @path com.yzh.homework
 */
public class Bubbling {
    public static void main(String[] args) {
        int [] arr = {8,7,6,1,4,2,9};
        for (int i = 0; i < arr.length-1; i++) {
            boolean flag = true;
            for (int j = 0; j< arr.length-1-i;j++){
                if(arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    flag = false;
                }
            }
            if(flag) return;
        }
        System.out.println(Arrays.toString(arr));
    }
}
